//
//  NSDictionary+Property.m
//  TJ
//
//  Created by 蔡国龙 on 17/3/13.
//  Copyright © 2017年 TJ. All rights reserved.
//

#import "NSDictionary+Property.h"

@implementation NSDictionary (Property)
- (void)createProperty
{
//    [UserModel currentUser];
    NSMutableString *codes = [NSMutableString string];
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        if ([obj isKindOfClass:[NSDictionary class]]) {
            [codes appendFormat:@"\n@property(nonatomic,strong) NSDictionary *%@;\n",key];
            
        }else if ([obj isKindOfClass:[NSArray class]]){
            [codes appendFormat:@"\n@property(nonatomic,strong) NSArray *%@;\n",key];
        }else if ([obj isKindOfClass:[NSString class]]){
            [codes appendFormat:@"\n@property(nonatomic,strong) NSString *%@;\n",key];
        }else if ([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
            [codes appendFormat:@"\n@property(nonatomic,assign) BOOL %@;\n",key];
        }else if ([obj isKindOfClass:[NSNumber class]]){
            [codes appendFormat:@"\n@property(nonatomic,strong) NSNumber *%@;\n",key];
        }else if ([obj isKindOfClass:[NSDate class]]){
            [codes appendFormat:@"\n@property(nonatomic,strong) NSDate *%@;\n",key];
        }else{
            [codes appendFormat:@"\n@property(nonatomic,strong) NSString *%@;\n",key];
        }
        
    }];
//
    if (codes.length >= 800) {
        NSString *str = [codes substringWithRange:NSMakeRange(0, 1020)];
        NSString *str1 = [codes substringWithRange:NSMakeRange(1021, 2041)];
        NSString *str2 = [codes substringWithRange:NSMakeRange(2042, codes.length - 2042)];

        ZWLog(@"属性生成如下--1:\n%@ ",str);
        ZWLog(@"属性生成如下--2:\n%@",str1);
        ZWLog(@"属性生成如下--3:\n%@",str2);
    }else{
        ZWLog(@"属性生成如下--:\n%@",codes);
    }
}
- (NSString *)descriptionWithLocale:(id)locale
{
    NSMutableString *string = [NSMutableString string];
    
    // 开头有个{
    [string appendString:@"{\n"];
    
    // 遍历所有的键值对
    [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        [string appendFormat:@"\t%@", key];
        [string appendString:@" : "];
        [string appendFormat:@"%@,\n", obj];
    }];
    
    // 结尾有个}
    [string appendString:@"}"];
    
    // 查找最后一个逗号
    NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
    if (range.location != NSNotFound)
        [string deleteCharactersInRange:range];
    
    return string;
}
@end


@implementation NSArray (Log)

- (NSString *)descriptionWithLocale:(id)locale
{
    NSMutableString *string = [NSMutableString string];
    
    // 开头有个[
    [string appendString:@"[\n"];
    
    // 遍历所有的元素
    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        [string appendFormat:@"\t%@,\n", obj];
    }];
    
    // 结尾有个]
    [string appendString:@"]"];
    
    // 查找最后一个逗号
    NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
    if (range.location != NSNotFound)
        [string deleteCharactersInRange:range];
    
    return string;
}

@end





